<?php
namespace admin\controllers;

use common\models\Banner;
use Yii;

/**
 * Banner图管理 
 */
class BannerController extends BaseController
{
    public $modelClass = 'common\models\Banner';
    public $searchModelClass = 'admin\models\BannerSearch';


    /**
     * 置顶
     */
    public function actionUp()
    {
        $id = Yii::$app->request->get('id');

        $banners = Banner::find();
        foreach ($banners->each() as $banner) {
            if ($banner->id == $id) { //如果是置顶的分类
                $banner->display_order = 255;
            } else {
                $banner->display_order > 0 ?  $banner->display_order -= 1 :  $banner->display_order;
            }
            if (!$banner->save()) {
                Yii::warning($banner->errors);    
            }
            
        }

        $this->back();
    }
}
